home *** CD-ROM | disk | FTP | other *** search
/ Internet.Works 40 / Issue 40.iso / pc / PCSoftware / DHTML Menu Builder 2.6 / dhtmlmen.exe / %AppDir% / code.dat < prev    next >
Encoding:
Text File  |  2000-10-26  |  15.5 KB  |  554 lines

  1. //COPYRIGHT
  2.  
  3.     var nStyle = new Array;
  4.     var hStyle = new Array;
  5.     var nLayer = new Array;
  6.     var hLayer = new Array;
  7.     var nTCode = new Array;
  8.  
  9.     var AnimStep = 0;
  10.     var AnimHnd = 0;
  11.     var HTHnd = new Array;
  12.     var DoFormsTweak = false;
  13.  
  14.     var mFrame;
  15.     var cFrame;
  16.  
  17.     var OpenMenus = new Array;
  18.     var SelCommand;
  19.     var nOM = 0;
  20.  
  21.     var mX;
  22.     var mY;
  23.     var xOff = 0;
  24.  
  25.     var HideSpeed = 200;
  26.  
  27. //BROWSERDETECTION
  28.  
  29.     if ((frames.length==0) && IsMac)
  30.         frames.top = window;
  31.  
  32.     if(IE)
  33.         xOff = 2;
  34. //CODEFRAME
  35.  
  36. //FX
  37.  
  38. //STYLECODE
  39.  
  40.     function GetCurCmd() {
  41.         //IE
  42.         //This function will return the current command under the mouse pointer.
  43.         //It will return null if the mouse is not over any command.
  44.         //------------------------------
  45.         //Version 1.3
  46.         //
  47.         var cc = mFrame.window.event.srcElement;
  48.         while((cc.id=="") && (cc.tagName!="TD")) {
  49.             cc = cc.parentElement;
  50.             if(cc==null)
  51.                 break;
  52.         }
  53.         return cc;
  54.     }
  55.  
  56.     function HoverSel(mode, imgLName, imgRName) {
  57.         //IE
  58.         //This is the function called every time the mouse pointer is moved over a command.
  59.         //------------------------------
  60.         //mode: 0 if the mouse is moving over the command and 1 if is moving away.
  61.         //imgLName: Name of the left image object, if any.
  62.         //imgRName: Name of the right image object, if any.
  63.         //------------------------------
  64.         //Version 9.3
  65.         //
  66.         var imgL = new Image;
  67.         var imgLRsc = new Image;
  68.         var imgR = new Image;
  69.         var imgRRsc = new Image;
  70.         var mc;
  71.  
  72.         if(mode==0 && OpenMenus[nOM].SelCommand!=null)
  73.             HoverSel(1);
  74.  
  75.         if(imgLName!="_")
  76.             var imgL = eval("mFrame.document.images['"+imgLName+"']");
  77.         if(imgRName!="_")
  78.             var imgR = eval("mFrame.document.images['"+imgRName+"']");
  79.  
  80.         if(mode==0) {
  81.             mc = GetCurCmd();
  82.             if(nOM>1)
  83.                 if(mc==OpenMenus[nOM-1].SelCommand)
  84.                     return false;
  85.             if(OpenMenus[nOM].SelCommand || nOM>1)
  86.                 while(!InMenu())
  87.                     Hide();
  88.             mc.style.cssText = hStyle[mc.id];
  89.             if(imgLName!='_') imgLRsc = eval(imgLName+"On");
  90.             if(imgRName!='_') imgRRsc = eval(imgRName+"On");
  91.             OpenMenus[nOM].SelCommand = mc;
  92.             OpenMenus[nOM].SelCommandPar = [imgLName,imgRName];
  93.         } else {
  94.             mc = (mode==1)?OpenMenus[nOM].SelCommand:OpenMenus[nOM].Opener;
  95.             imgLName = (mode==1)?OpenMenus[nOM].SelCommandPar[0]:OpenMenus[nOM].OpenerPar[0];
  96.             imgRName = (mode==1)?OpenMenus[nOM].SelCommandPar[1]:OpenMenus[nOM].OpenerPar[1];
  97.             mc.style.background = "";
  98.             mc.style.cssText = nStyle[mc.id];
  99.             if(imgLName!='_') imgLRsc = eval(imgLName+"Off");
  100.             if(imgRName!='_') imgRRsc = eval(imgRName+"Off");
  101.             window.status = "";
  102.             OpenMenus[nOM].SelCommand = null;            
  103.         }
  104.  
  105.         if(imgLName!='_') {
  106.             imgL = eval("mFrame.document.images."+imgLName);
  107.             imgL.src = imgLRsc.src;
  108.         }
  109.         if(imgRName!='_') {
  110.             imgR = eval("mFrame.document.images."+imgRName);
  111.             imgR.src = imgRRsc.src;
  112.         }
  113.  
  114.         return true;
  115.     }
  116.  
  117.     function NSHoverSel(mode, mc, bcolor, w, h) {
  118.         //NS
  119.         //This is the function called every time the mouse pointer is moved over or away from a command.
  120.         //------------------------------
  121.         //mode: 0 if the mouse is moving over the command and 1 if is moving away.
  122.         //mc: Name of the layer that corresponds to the selected command.
  123.         //n: Unique ID that identifies this command. Used to retrieve the data from the nLayer or hLayer array.
  124.         //bcolor: Background color of the command. Ignored if the group uses a background image.
  125.         //w: Width of the command's layer.
  126.         //h: Height of the command's layer.
  127.         //------------------------------
  128.         //Version 10.5
  129.         //
  130.         var n;
  131.         var LayerHTM;
  132.         if(mode==0 && OpenMenus[nOM].SelCommand!=null)
  133.             NSHoverSel(1);
  134.         
  135.         if(mode==0) {
  136.             n = CBparseInt(mc.name.substr(2));
  137.             if(nOM>1)
  138.                 if(mc==OpenMenus[nOM-1].SelCommand)
  139.                     return false;
  140.             while(!InMenu())
  141.                 Hide();
  142.             LayerHTM = hLayer[n];
  143.             OpenMenus[nOM].SelCommand = mc;
  144.             OpenMenus[nOM].SelCommandPar = [mc.bgColor,w,h];
  145.             mc.bgColor = bcolor;
  146.         } else {
  147.             mc = (mode==1)?OpenMenus[nOM].SelCommand:OpenMenus[nOM].Opener;
  148.             bcolor = (mode==1)?OpenMenus[nOM].SelCommandPar[0]:OpenMenus[nOM].OpenerPar[0];
  149.             w = (mode==1)?OpenMenus[nOM].SelCommandPar[1]:OpenMenus[nOM].OpenerPar[1];
  150.             h = (mode==1)?OpenMenus[nOM].SelCommandPar[2]:OpenMenus[nOM].OpenerPar[2];
  151.             n = CBparseInt(mc.name.substr(2));
  152.             LayerHTM = nLayer[n];
  153.             if(mc.parentLayer.background.src!="")
  154.                 mc.bgColor = null;
  155.             else
  156.                 mc.bgColor = bcolor;
  157.             window.status = "";
  158.             OpenMenus[nOM].SelCommand = null;
  159.         }
  160.         mc.resizeTo(w,h);
  161.         mc.document.open();
  162.         mc.document.write(LayerHTM);
  163.         mc.document.close();
  164.  
  165.         return true;
  166.     }
  167.  
  168.     function Hide() {
  169.         //IE,NS
  170.         //This function hides the last opened group and it keeps hiding all the groups until
  171.         //no more groups are opened or the mouse is over one of them.
  172.         //Also takes care of reseting any highlighted commands.
  173.         //------------------------------
  174.         //Version 3.2
  175.         //
  176.  
  177.         if(AnimHnd)
  178.             window.clearTimeout(AnimHnd);
  179.  
  180.         if(OpenMenus[nOM].SelCommand!=null) {
  181.             if(IE) HoverSel(1);
  182.             if(NS) NSHoverSel(1);
  183.         }
  184.         if(OpenMenus[nOM].Opener!=null) {
  185.             if(IE) HoverSel(3);
  186.             if(NS) NSHoverSel(3);
  187.         }
  188.  
  189.         OpenMenus[nOM].visibility = "hidden";
  190.         window.clearTimeout(HTHnd[nOM]);
  191.         HTHnd[nOM] = 0;
  192.         nOM--;
  193.  
  194.         if(nOM>0)
  195.             if(!InMenu())
  196.                 HTHnd[nOM] = window.setTimeout("Hide()", HideSpeed);
  197.  
  198.         if(nOM==0)
  199.             FormsTweak("visible");
  200.     }
  201.  
  202.     function ShowMenu(mName, x, y, isCascading) {
  203.         //IE,NS
  204.         //This is the main function to show the menus when a hotspot is triggered or a cascading command is activated.
  205.         //------------------------------
  206.         //mName: Name of the <div> or <layer> to be shown.
  207.         //x: Left position of the menu.
  208.         //y: Top position of the menu.
  209.         //isCascading: True if the menu has been triggered from a command, and not from a hotspot.
  210.         //------------------------------
  211.         //Version 14.0
  212.         //
  213.         x = CBparseInt(x);
  214.         y = CBparseInt(y);
  215.         if(AnimHnd && nOM>0) {
  216.             AnimStep=100;
  217.             Animate();
  218.         }
  219.         if(IE)
  220.             var Menu = mFrame.document.all[mName];
  221.         if(NS)
  222.             var Menu = mFrame.document.layers[mName];
  223.         if(!Menu)
  224.             return false;
  225.         if(IE)
  226.             Menu = Menu.style;
  227.         if(Menu==OpenMenus[nOM] || HTHnd[nOM])
  228.             return false;
  229.         
  230.         Menu.Opener = nOM>0?OpenMenus[nOM].SelCommand:null;
  231.         Menu.OpenerPar = nOM>0?OpenMenus[nOM].SelCommandPar:null;
  232.         Menu.SelCommand = null;
  233.         
  234.         if(!isCascading)
  235.             HideAll();
  236.  
  237.         var pW = GetWidthHeight()[0] + GetLeftTop()[0];
  238.         var pH = GetWidthHeight()[1] + GetLeftTop()[1];
  239.         
  240.         if(IE) {
  241.             if(isCascading) {
  242.                 x = CBparseInt(OpenMenus[nOM].left) + CBparseInt(OpenMenus[nOM].width) - 6;
  243.                 y = y + CBparseInt(OpenMenus[nOM].top) - 5;
  244.                 Menu.left = (x+CBparseInt(Menu.width)>pW)?CBparseInt(OpenMenus[nOM].left) - CBparseInt(Menu.width) + 6:x;
  245.                 Menu.top =  (y+CBparseInt(Menu.height)>pH)?pH - CBparseInt(Menu.height):y;
  246.             } else {
  247.                 Menu.left = (x+CBparseInt(Menu.width)>pW)?pW - CBparseInt(Menu.width):x;
  248.                 Menu.top =  (y+CBparseInt(Menu.height)>pH)?pH - CBparseInt(Menu.height):y;
  249.             }
  250.             if(!IsMac)
  251.                 Menu.clip = "rect(0 0 0 0)";
  252.         }
  253.         if(NS) {
  254.             if(isCascading) {
  255.                 x = OpenMenus[nOM].left + OpenMenus[nOM].clip.width - 6;
  256.                 y = OpenMenus[nOM].top + OpenMenus[nOM].SelCommand.top;
  257.                 x = (x+Menu.w>pW)?OpenMenus[nOM].left - Menu.w + 6:x;
  258.                 y = (y+Menu.h>pH)?pH - Menu.h:y;
  259.             } else {
  260.                 x = (x+Menu.w>pW)?pW - Menu.w:x;
  261.                 y = (y+Menu.h>pH)?pH - Menu.h:y;
  262.             }
  263.             Menu.clip.width = 0;
  264.             Menu.clip.height = 0;
  265.             Menu.moveToAbsolute(x,y);
  266.         }
  267.         if(isCascading)
  268.             Menu.zIndex = CBparseInt(OpenMenus[nOM].zIndex) + 1;
  269.         Menu.visibility = "visible";
  270.         OpenMenus[++nOM] = Menu;
  271.         HTHnd[nOM] = 0;
  272.         if((IE && !IsMac) || NS)
  273.             AnimHnd = window.setTimeout("Animate()", 10);
  274.         FormsTweak("hidden");
  275.  
  276.         return true;
  277.     }
  278.  
  279.     function Animate() {
  280.         //IE,NS
  281.         //This function is called by ShowMenu every time a new group must be displayed and produces the predefined unfolding effect.
  282.         //Currently is disabled for Navigator, because of some weird bugs we found with the clip property of the layers.
  283.         //------------------------------
  284.         //Version 1.9
  285.         //
  286.         var r = '';
  287.         var nw = nh = 0;
  288.         switch(fx) {
  289.             case 1:
  290.                 if(IE) r = "0 " + AnimStep + "% " + AnimStep + "% 0";
  291.                 if(NS) nw = AnimStep; nh = AnimStep;
  292.                 break;
  293.             case 2:
  294.                 if(IE) r = "0 100% " + AnimStep + "% 0";
  295.                 if(NS) nw = 100; nh = AnimStep;
  296.                 break;
  297.             case 3:
  298.                 if(IE) r = "0 " + AnimStep + "% 100% 0";
  299.                 if(NS) nw = AnimStep; nh = 100;
  300.                 break;
  301.             case 0:
  302.                 if(IE) r = "0 100% 100% 0";
  303.                 if(NS) nw = 100; nh = 100;
  304.                 break;
  305.         }
  306.         with(OpenMenus[nOM]) {
  307.             if(IE)
  308.                 clip =  "rect(" + r + ")";
  309.             if(NS) {
  310.                 clip.width = w*(nw/100);
  311.                 clip.height = h*(nh/100);
  312.             }
  313.         }
  314.         AnimStep += 20;
  315.         if(AnimStep<=100)
  316.             AnimHnd = window.setTimeout("Animate()",25);
  317.         else {
  318.             window.clearTimeout(AnimHnd);
  319.             AnimStep = 0;
  320.             AnimHnd = 0;
  321.         }
  322.     }
  323.     
  324.     function InMenu() {
  325.         //IE,NS
  326.         //This function returns true if the mouse pointer is over the last opened menu.
  327.         //------------------------------
  328.         //Version 1.6
  329.         //
  330.         var m = OpenMenus[nOM];
  331.         if(!m)
  332.             return false;
  333.         if(IE&&BV==4)
  334.             SetPointerPos();
  335.         var l = CBparseInt(m.left) + xOff;
  336.         var r = l+((IE)?CBparseInt(m.width):m.clip.width) - xOff;
  337.         var t = CBparseInt(m.top) + xOff;
  338.         var b = t+((IE)?CBparseInt(m.height):m.clip.height) - xOff;
  339.         return ((mX>=l && mX<=r) && (mY>=t && mY<=b));
  340.     }
  341.  
  342.     function SetPointerPos(e) {
  343.         //IE,NS
  344.         //This function sets the mX and mY variables with the current position of the mouse pointer.
  345.         //------------------------------
  346.         //e: Only used under Navigator, corresponds to the Event object.
  347.         //------------------------------
  348.         //Version 1.0
  349.         //
  350.         if(IE) {
  351.             if(event==null)
  352.                 if(mFrame.window.event==null)
  353.                     return;
  354.                 else
  355.                     e = mFrame.window.event;
  356.             else
  357.                 e = event;
  358.             mX = e.clientX + mFrame.document.body.scrollLeft;
  359.             mY = e.clientY + mFrame.document.body.scrollTop;
  360.         }
  361.         if(NS) {
  362.             mX = e.pageX;
  363.             mY = e.pageY;
  364.         }
  365.     }
  366.     
  367.  
  368.     function HideMenus(e) {
  369.         //IE,NS
  370.         //This function checks if the mouse pointer is on a valid position and if the current menu should be kept visible.
  371.         //The function is called every time the mouse pointer is moved over the document area.
  372.         //------------------------------
  373.         //e: Only used under Navigator, corresponds to the Event object.
  374.         //------------------------------
  375.         //Version 24.3
  376.         //
  377.         SetPointerPos(e);
  378.         if(nOM>0)
  379.             if(OpenMenus[nOM].SelCommand!=null)
  380.                 while(!InMenu() && !HTHnd[nOM]) {
  381.                     HTHnd[nOM] = window.setTimeout("Hide()", HideSpeed);
  382.                     if(nOM==0)
  383.                         break;
  384.                 }
  385.     }
  386.     
  387.     function FormsTweak(state) {
  388.         //IE
  389.         //This is an undocumented function, which can be used to hide every listbox (or combo) element on a page.
  390.         //This can be useful if the menus will be displayed over an area where is a combo box, which is an element that cannot be placed behind the menus and it will always appear over the menus resulting in a very undesirable effect.
  391.         //------------------------------
  392.         //Version 2.0
  393.         //
  394.         if(DoFormsTweak && IE)
  395.             for(var f = 0; f <= (mFrame.document.forms.length - 1); f++)
  396.                 for(var e = 0; e <= (mFrame.document.forms[f].elements.length - 1); e++)
  397.                     if(mFrame.document.forms[f].elements[e].type=="select-one")
  398.                         mFrame.document.forms[f].elements[e].style.visibility = state;
  399.     }
  400.  
  401.     function execURL(url, tframe) {
  402.         //IE,NS
  403.         //This function is called every time a command is triggered to jump to another page or execute some javascript code.
  404.         //------------------------------
  405.         //url: Encrypted URL that must be opened or executed.
  406.         //tframe: If the url is a document location, tframe is the target frame where this document will be opened.
  407.         //------------------------------
  408.         //Version 1.1
  409.         //
  410.         HideAll();
  411.         window.setTimeout("execURL2('" + url + "', '" + tframe + "')", 100);
  412.     }
  413.  
  414.     function execURL2(url, tframe) {
  415.         //IE,NS
  416.         //This function is called every time a command is triggered to jump to another page or execute some javascript code.
  417.         //------------------------------
  418.         //url: Encrypted URL that must be opened or executed.
  419.         //tframe: If the url is a document location, tframe is the target frame where this document will be opened.
  420.         //------------------------------
  421.         //Version 1.0
  422.         //
  423.         tframe = rStr(tframe);
  424.         var fObj = eval(tframe);
  425.         url = rStr(url);
  426.         if(url.indexOf("javascript")!=url.indexOf("vbscript"))
  427.             eval(url);
  428.         else
  429.             fObj.location.href = url;
  430.     }
  431.  
  432.     function rStr(s) {
  433.         //IE,NS
  434.         //This function is used to decrypt the URL parameter from the triggered command.
  435.         //------------------------------
  436.         //Version 1.1
  437.         //
  438.         s = xrep(s,"\x1E","'");
  439.         s = xrep(s,"\x1D","\x22");
  440.         s = xrep(s,"\x1C",",");
  441.         return s;
  442.     }
  443.  
  444.     function xrep(s, f, n) {
  445.         //IE,NS
  446.         //This function looks for any occurrence of the f string and replaces it with the n string.
  447.         //------------------------------
  448.         //Version 1.0
  449.         //
  450.         var tmp = s.split(f);
  451.         return tmp.join(n);
  452.     }
  453.  
  454.     function hNSCClick(e) {
  455.         //NS
  456.         //This function executes the selected command's trigger code.
  457.         //------------------------------
  458.         //Version 1.0
  459.         //
  460.         eval(this.TCode);
  461.     }
  462.     
  463.     function CBparseInt(n) {
  464.     //NS
  465.     //This function fixes a bug in Navigator's parseInt() function for the Mac.
  466.     //------------------------------
  467.     //Version 1.0
  468.     //
  469.         return IsMac?n:parseInt(n);
  470.     }
  471.  
  472.     function HideAll() {
  473.         //IE,NS
  474.         //This function will hide all the currently opened menus.
  475.         //------------------------------
  476.         //Version 1.0
  477.         //
  478.         while(nOM>0)
  479.             Hide();
  480.     }
  481.  
  482.     function GetLeftTop() {
  483.         //IE,NS
  484.         //This function returns the scroll bars position on the menus frame.
  485.         //------------------------------
  486.         //Version 1.0
  487.         //
  488.         if(IE)
  489.             return [mFrame.document.body.scrollLeft,mFrame.document.body.scrollTop];
  490.         if(NS)
  491.             return [mFrame.pageXOffset,mFrame.pageYOffset];
  492.     }
  493.  
  494.     function GetWidthHeight() {
  495.         //IE,NS
  496.         //This function returns the width and height of the menus frame.
  497.         //------------------------------
  498.         //Version 1.0
  499.         //
  500.         if(IE)
  501.             return [mFrame.document.body.clientWidth,mFrame.document.body.clientHeight];
  502.         if(NS)
  503.             return [mFrame.innerWidth,mFrame.innerHeight];
  504.     }
  505.  
  506.     function SetUpEvents() {
  507.         //IE,NS
  508.         //This function initializes the frame variables and setups the event handling.
  509.         //------------------------------
  510.         //Version 1.2
  511.         //
  512.         if(typeof(mFrame)=="undefined")
  513.         //MENUFRAME
  514.         if(typeof(mFrame)=="undefined")
  515.             window.setTimeout("SetUpEvents()",10);
  516.         else {
  517.             if(NS) {
  518.                 mFrame.captureEvents(Event.MOUSEMOVE);
  519.                 mFrame.onmousemove = HideMenus;
  520.                 PrepareEvents();
  521.             }
  522.             mFrame.document.onmousemove = HideMenus;
  523.             document.onmousemove = HideMenus;
  524.         }
  525.     }
  526.  
  527.     function PrepareEvents() {
  528.         //NS
  529.         //This function is called right after the menus are rendered.
  530.         //It has been designed to attach the OnClick event to the <layer> tag. This is being
  531.         //done this way because Navigator does not support a click inline event capturing on
  532.         //the layer tag... duh!
  533.         //------------------------------
  534.         //Version 2.1
  535.         //
  536.         for(var l=0; l<mFrame.document.layers.length; l++) {
  537.             var lo = mFrame.document.layers[l];
  538.             lo.w = lo.clip.width;
  539.             lo.h = lo.clip.height;
  540.             for(var sl=0; sl<lo.layers.length; sl++) {
  541.                 var slo = mFrame.document.layers[l].layers[sl];
  542.                 if(slo.name.indexOf("EH")>0) {
  543.                     slo.document.captureEvents(Event.CLICK);
  544.                     slo.document.onclick = hNSCClick;
  545.                     slo.document.TCode = nTCode[slo.name.split("EH")[1]];
  546.                 }                    
  547.             }
  548.         }
  549.     }
  550.  
  551. //BROWSERCODE
  552.  
  553. //EXPAND
  554.